/* GUI CONVERTED from ardrmtd.p (converter v1.76) Thu Mar 20 08:07:17 2003 */
/* ardrmtd.p - AR DEBIT/CREDIT MEMO MAINTENANCE GET BATCH INFORMATION       */
/* Copyright 1986-2003 QAD Inc., Carpinteria, CA, USA.                      */
/* All rights reserved worldwide.  This is an unpublished work.             */
/* $Revision: 1.6.1.8 $                                                     */
/*V8:ConvertMode=Maintenance                                                */
/* REVISION: 7.2      LAST MODIFIED: 06/27/94   by: pmf *FP09*              */
/* REVISION: 7.3      LAST MODIFIED: 06/08/96   by: wjk *G1XC*              */

/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane         */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan        */
/* REVISION: 8.6E     LAST MODIFIED: 10/04/98   BY: *J314* Alfred Tan        */
/* REVISION: 9.0      LAST MODIFIED: 03/10/99   BY: *M0B3* Michael Amaladhas */
/* REVISION: 9.0      LAST MODIFIED: 03/13/99   BY: *M0BD* Alfred Tan        */
/* REVISION: 9.1      LAST MODIFIED: 10/22/99   BY: *N04P* Robert Jensen     */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane  */
/* REVISION: 9.1      LAST MODIFIED: 08/11/00   BY: *N0KK* jyn               */
/* Old ECO marker removed, but no ECO header exists *F0PN*                   */
/* Revision: 1.6.1.7     BY: Alok Thacker   DATE: 07/19/01 ECO: *M169*      */
/* $Revision: 1.6.1.8 $    BY: Piotr Witkowicz DATE: 03/14/03 ECO: *P0NP*     */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/
{mfdeclre.i}
{cxcustom.i "ARDRMTD.P"}
{gplabel.i} /* EXTERNAL LABEL INCLUDE */

/* ********** Begin Translatable Strings Definitions ********* */

&SCOPED-DEFINE ardrmtd_p_1 "Batch"
/* MaxLen: Comment: */

/* ********** End Translatable Strings Definitions ********* */

define shared variable ba_recno        as   recid.
define shared variable batch           like ar_batch label {&ardrmtd_p_1}.
define shared variable bactrl          like ba_ctrl.
define shared variable bamodule        like ba_module.
define shared variable first_in_batch  like mfc_logical.

{&ARDRMTD-P-TAG1}
/* LOGISTICS TABLES */
{lgardefs.i &type="lg"}

/* DEFINE SHARED FRAME A */
{ardrfma.i}

do transaction:
/*GUI*/ if global-beam-me-up then undo, leave.

   clear frame a.
/*GUI*/ RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
   status input.

   assign
      bactrl   = 0
      batch    = ""
      bamodule = "AR".

   /* NO TERMINAL FOR lOGISTICS.  SET BATCH TO AUTOSET. */
   if not lgData
   then
      set
         batch
      with frame a.
   else
      batch = "".

   if batch <> ""
   then do:
      /* MODIFIED CONDITION TO INCLUDE CHECK FOR */
      /* MULTIPLE ar_type IN SAME BATCH          */
      if not can-find(first ar_mstr
                      where ar_batch             = batch
                      and   index("MFI",ar_type) <> 0)
      then
         if can-find(first ar_mstr
                     where ar_batch             = batch
                     and   index("MFI",ar_type) = 0)
         then do:
             /* MESSAGE NUMBER CHANGED             */
             /* FROM 1170 - NOT A VALID BATCH      */
             /* TO   1182 - BATCH ALREADY ASSIGNED */
            {pxmsg.i &MSGNUM=1182 &ERRORLEVEL=3}
            pause.
            next-prompt batch with frame a.
            undo, retry.
         end. /* IF CAN-FIND (FIRST ar_mstr ... */

      find ba_mstr
         where ba_batch  = batch
         and   ba_module = "AR"
         exclusive-lock no-error.
      /* SEE IF SALES ORDER BATCH (ar_type = "I") WITH THIS */
      /* BATCH NUMBER ALREADY EXISTS                        */
      if not available ba_mstr then
      find ba_mstr
         where ba_batch  = batch
         and   ba_module = "SO"
         exclusive-lock no-error.
      if available ba_mstr
      then do:
         {&ARDRMTD-P-TAG2}
         assign
            bactrl = ba_ctrl
            /*INSURE BATCH TOTAL = SUM OF MEMOS*/
            ba_total = 0.

         for each ar_mstr
            where ar_batch = batch no-lock:
            ba_total = ba_total + ar_amt.
         end.

         display
            ba_total
         with frame a.

         /* IF THIS BATCH IS A "SO" BATCH, WARN USER THAT NO */
         /* NEW MEMOS CAN BE ADDED TO THIS BATCH             */
         if ba_module = "SO"
         then do:
            {pxmsg.i &MSGNUM=1185 &ERRORLEVEL=2}
            /* BATCH ALREADY CONTAINS         */
            /* INVOICES - CAN'T ADD NEW MEMOS */
            bamodule = "SO".
         end.
      end. /* if available ba_mstr */
      else
          display
             0 @ ba_total
          with frame a.
   end. /* if batch <> "" */
   else
      display
         0 @ bactrl
         0 @ ba_total
      with frame a.

   /* IF LOGISTICS, LEAVE BACTRL ALONE. */
   if not lgData
   then
      update
         bactrl
      with frame a.

   ba_recno = 0.
   if available ba_mstr
   /* and bactrl <> 0 */
   then
      assign
         ba_ctrl  = bactrl
         ba_recno = recid(ba_mstr).

   first_in_batch = yes.
end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* do transaction */
